﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WfTimedExecService
{
    public class Service_Log
    {
        #region 服务日志
        /// <summary>
        /// 服务日志
        /// </summary>
        /// <param name="type">记录类型[启动，停止]</param>
        /// <param name="msg">消息</param>
        public static void Log(string type,string msg)
        {
            string path = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, string.Format("{0}.txt", DateTime.Now.ToString("yyyyMMdd")));  
           // string path = System.Web.HttpContext.Current.Server.MapPath(string.Format("/ErrorLog/{0}.txt", DateTime.Now.ToString("yyyyMMdd")));
            string[] str = new string[4];
            str[0] = "类型：" + type + "\r\n";
            str[1] = "时间：" + DateTime.Now.ToString() + "\r\n";
            str[2] = "消息：" + msg + "\r\n";
            str[3] = "----------------------------------------------------------------\r\n";
            StreamWriter rw;
            if (!File.Exists(path))
                rw = File.CreateText(path);
            else
                rw = File.AppendText(path);
            rw.WriteLine(string.Format("{0}{1}{2}{3}", str[0], str[1], str[2], str[3]));
            rw.Flush();
            rw.Close();
        }
        #endregion
    }
}
